//菜单对应的图标
import {
  AppstoreOutlined, MailOutlined, SettingOutlined, AccountBookOutlined,
  ExportOutlined
} from '@ant-design/icons';

//菜单配置数组
const menu_arr =  [
    //后台首页（销售统计-订单统计）
    {
      path:"home",
      role:['super','normal'],
      label: "后台首页",
      key:"home",
      icon:<AccountBookOutlined />
    },
    {
      path: 'order_home',
      role:['super','normal'],
      label:"订单管理", //为了生成菜单名称
      key:"order_home",//为了生成菜单时点击跳转
      icon:<AccountBookOutlined />
    },
    {
      key:"goods_manger",
      label:"商品管理",
      role:['super','normal'],
      children: [
        {
          path:"product_list",
          role:['super','normal'],
          label:"商品列表", //为了生成菜单名称
          key:"product_list"//为了生成菜单时点击跳转
        },
        {
          path:"product_add",
          role:['super','normal'],
          label: "商品添加",
          key:"product_add"
        },
        {
          path:"goods_cate_mange",
          role:['super','normal'],
          label:"分类管理",
          key:"goods_cate_mange",
        }
      ]
    },
    {
      path:"shop_home",
      role:['super','normal'],
      label: "店铺管理",
      key:"shop_home"
    },
    {
      key:"account_manger",
      label:"账号管理",
      role:['super','normal'],
      children: [
        {
          path:"account_list",
          role:['super'], //只有admin角色才可以
          label: "账号列表",
          key:"account_list"
        },
        {
          path:"account_add",
          role:['super'],//只有admin角色才可以
          label: "添加账号",
          key:"account_add",
        },
        {
          path:"edit_password",
          role:['super','normal'],
          label: "修改密码",
          key:"edit_password",
        },
      ]
    },
    //后台首页（销售统计-商品统计）
    {
      label:"销售统计",
      key:"sale_home",
      role:['super','normal'],
      children:[
        {
          path:"goods_analysis",
          role:['super'],
          label: "商品统计",
          key:"goods_analysis",
        },
        {
          path:"index",
          role:['super','normal'],
          label: "订单统计",
          key:"index",
        },
      ]
    }
];

//定义方法，获取角色对应的菜单
export function getUserMenu(role,arr){

  let arr_new = arr.filter((v,k)=>{
      let vv = v.role || []; //角色数组
      
      if(vv&&vv.includes(role)) {
          // return v;
          // 子路由处理
          if(v.children){
              console.log("children:",v.children)

              let children = getUserMenu(role,v.children) //重新调一次自己
              v['children'] = children;
          }
          return v;//返回新的元素
      }
  })
  return arr_new;
}

//导出
export default menu_arr;